package org.argetr.resim.ui.rcp.rcp;


import org.argetr.resim.ResimProjectEditor;
import org.argetr.resim.ShapesEditor;
import org.argetr.resim.proc.tools.ShapeDiagramRunner;
import org.argetr.resim.ui.model.ShapesDiagram;
import org.eclipse.jface.action.Action;
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.IWorkbenchWindow;



public class RunProjectAction extends Action{
	public final static String RUN_ACTION_ID="PROJECT_RUN_ACTION";

	private IWorkbenchWindow _workbenchWindow;
	
	public RunProjectAction(IWorkbenchWindow window,String displayName) {
		setId(RUN_ACTION_ID);
		setText(displayName);
		_workbenchWindow = window;
	}
	
	public void run() {
		try
		{	
			IEditorPart lEditorPart = _workbenchWindow.getActivePage().getActiveEditor();
			ResimProjectEditor rpe = (ResimProjectEditor)lEditorPart;			
			ShapesDiagram lShapesDiagram = ((ShapesEditor)rpe.getActiveEditor()).getModel();
			ShapeDiagramRunner.setShapesDiagram(lShapesDiagram);
			ShapeDiagramRunner.run();			
		}
		catch(Exception exp)
		{
			System.err.println(exp.getMessage());
		}
	}
}
